package com.example.teacher.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.teacher.R
import com.example.teacher.data.Attendance

/**
 *@Created by 覃德玮 on 2021/9/6 10:32
 *@Email: chadewik@foxmail.com
 *@Description:
 */
class ListAdapter(listData: List<Attendance>) : RecyclerView.Adapter<ViewHolder>() {
    val data:List<Attendance>
    init {
        data=listData
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {

        val holder = ViewHolder(
            LayoutInflater.from(parent.context)
                .inflate(R.layout.list_item, parent, false)
        )
        return holder
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.coursename.text=data[position].courseName
        holder.coursetime.text=data[position].time
        holder.attendance.text=data[position].number.toString()
        holder.exit.text=(data[position].number-data[position].absentNum).toString()
        holder.courseidtv.text=data[position].courseId

        holder.itemView.setOnClickListener{

        }

    }

    override fun getItemCount(): Int {
       return data.size
    }


}
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
    val coursename:TextView=itemView.findViewById(R.id.name)
    val coursetime:TextView=itemView.findViewById(R.id.time)
    val attendance:TextView=itemView.findViewById(R.id.attendance)
    val exit:TextView=itemView.findViewById(R.id.exitnum)
    val courseidtv:TextView=itemView.findViewById(R.id.courseIdtv)
}
